package com.dyw.Day32;

/**
 * @author Devil
 * @create 2022-04-10 0:22
 */
public class Demo02 {
    public ListNode middleNode(ListNode head) {
        ListNode listNode = head;
        int n = 0;
        while(listNode!=null){
            n++;
            listNode = listNode.next;
        }
        for (int i=1; i<n/2+1;i++){
            head = head.next;
        }

        return head;
    }
}
class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}